//
//  UserInfoViewController.m
//  RoadMaintain
//
//  Created by 岳学坤 on 2017/4/24.
//  Copyright © 2017年 岳学坤. All rights reserved.
//

#import "UserInfoViewController.h"
#import "UserInfoTableViewCell.h"
#import "ResetPasswordViewController.h"
#define UserCellId @"cellid1"
@interface UserInfoViewController ()
{
    NSArray *contentArray;
}
@property (nonatomic,strong) NSDictionary *dic;
@property (nonatomic,strong) UIView *footerView;
@end

@implementation UserInfoViewController
#pragma mark - Life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    [self resetNav];
    [self setTableFooterView];
    [self setWebData];
    [self.dataArray addObjectsFromArray:@[@"登录账号",@"用户名",@"用户类型",@"单位",@"部门"]];
}

#pragma mark - Property

#pragma mark - UI
- (void)resetNav{
    [self setTheBackBtn];
    self.myTitle.text = @"个人信息";
    [self.tableView registerClass:[UserInfoTableViewCell class] forCellReuseIdentifier:UserCellId];
}
- (void)setTableFooterView{
    self.footerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 200*WidthRate)];
    self.footerView.backgroundColor = [PublicMethod colorWithHexString:@"#eaeaea" andAlpha:1];
    self.tableView.tableFooterView = self.footerView;
    
    UIButton *submit = [UIButton buttonWithType:UIButtonTypeCustom];
    
    submit.backgroundColor = MAIN_Color;
    [submit setTitleColor:Bai_Color forState:UIControlStateNormal];
    [submit setTitle:@"修改密码" forState:UIControlStateNormal];
    [submit addTarget:self action:@selector(submit) forControlEvents:UIControlEventTouchUpInside];
    submit.titleLabel.font = [UIFont systemFontOfSize:17*ZitiRate];
    [self.footerView addSubview:submit];
    [submit mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-120*WidthRate);
        make.height.mas_equalTo(42*HeightRate);
        make.right.mas_equalTo(-15*WidthRate);
        make.left.mas_equalTo(15*WidthRate);
    }];
}
#pragma mark - UI Response
- (void)submit{
    ResetPasswordViewController *con = [[ResetPasswordViewController alloc]init];
    [self.navigationController pushViewController:con animated:YES];
}
#pragma mark - Data handle
- (void)setWebData{
    [MBProgressHUD showHUDAddedTo:self.tableView animated:YES];
    [NetWorkTool getUserInfoblock:^(id data) {
       [MBProgressHUD hideAllHUDsForView:self.tableView animated:NO];
        if (data) {
            self.dic = data[@"data"];
            [self.tableView reloadData];
        }else{
            [MBProgressHUD showTextHUDAddedTo:self.view Msg:@"网络错误，就检查网络" animated:YES];
        }
    }];
}
#pragma mark - Delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 50*HeightRate;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UserInfoTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:UserCellId];
    cell.titleLab.text = self.dataArray[indexPath.row];
    switch (indexPath.row) {
        case 0:
        {
          cell.contentLab.text = self.dic[@"loginId"];
        }
            break;
        case 1:
        {
            cell.contentLab.text = self.dic[@"userName"];
        }
            break;
        case 2:
        {
            cell.contentLab.text = self.dic[@"userTypeCn"];
        }
            break;
        case 3:
        {
            cell.contentLab.text = self.dic[@"orgName"];
        }
            break;
        default:
        {
            cell.contentLab.text = self.dic[@"departmentName"];
        
            break;
    }
    }
    return  cell;

}


@end
